<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>props use</title>
</head>
<body>

<div id="test"></div>
<div id="test2"></div>

<script src="js/react.development.js" crossorigin></script>
<script src="js/react-dom.development.js" crossorigin></script>
<script src="js/prop-types.js"></script>
<script src="js/babel.js"></script>


<script type="text/babel">
    class Person extends React.Component {
        // 为组件props参数提供校验
        static propTypes = {
            name: PropTypes.string.isRequired,
            sex: PropTypes.string,
            age: PropTypes.number,
        }
        // 指定默认值
        static defaultProps = {
            sex: 'woman',
            age: 18
        }

        render() {
            // props 属性是只读的
            let {name, sex, age} = this.props;
            return (
                <ul>
                    <li>姓名：{name}</li>
                    <li>性别：{sex}</li>
                    <li>年龄：{age + 1}</li>
                </ul>
            )
        }
    }

    // ...{} rest运算符
    ReactDOM.render(<Person {...{name: 'LouNa', age: 27, sex: 'man'}}/>, document.getElementById('test'))
    ReactDOM.render(<Person {...{name: '张三'}}/>, document.getElementById('test2'))
</script>

</body>
</html>